#ifndef SRV_H
#define SRV_H

#define SSYNC asm("ssync;")
#define TRUE 1
#define FALSE 0

#define SCCB_ON  1   // enables SCCB mode for I2C (used by OV9655 camera)
#define SCCB_OFF 0

#define PWM_OFF 0
#define PWM_PWM 1
#define PWM_PPM 2
#define PWM_UART 3

#define FOUR_TWO_ZERO 1
#define FOUR_TWO_TWO  2

/* flash usage */
#define BOOT_SECTOR  0x00000000  // address in SPI flash of boot image 
#define FLASH_SECTOR 0x00040000  // address in SPI flash of user flash sector  

/* SDRAM allocation */
#define FLASH_BUFFER 0x00100000  // address in SDRAM for buffering flash and xmodem
#define SPI_BUFFER   0x00180000  // buffer for transfer of data via SPI bus
#define HEAPSTART    0x00200000  // put this above FLASH_BUFFER 
#define HEAPSIZE     0x00D00000  // 13MB for now - leave 1MB for JPEG buffer
#define DMA_BUF1     0x01000000  // address in SDRAM for DMA transfer of frames from camera
#define DMA_BUF2     0x01300000  //   second DMA buffer for double buffering
#define FRAME_BUF    0x01600000  // address in SDRAM for staging images for processing/jpeg
#define FRAME_BUF2   0x01900000  //   second buffer for storing reference frame
#define FRAME_BUF3   0x01C00000  //   another buffer for edge data
#define JPEG_BUF     0x00F00000  // address in SDRAM for JPEG compressed image

/* Misc Init */
void init_io ();
void clear_sdram ();
void reset_cpu ();

/* Serial outputs */
void serial_out_version ();
void serial_out_time ();
void serial_out_flashbuffer ();

/* LED's */
void led0_on();
void led1_on();

/* Camera */
void send_frame ();
void grab_reference_frame ();
void compute_frame_diff (unsigned char *, unsigned char *, int, int);
void set_edge_thresh();
void disable_frame_diff ();
void camera_setup ();
void camera_reset (unsigned int width);
void change_image_quality ();
void set_caption (unsigned char *str, unsigned int width);

/* Transfer */
void xmodem_receive ();

/* Flash */
void read_user_flash ();
void write_user_flash ();
void write_boot_flash ();
void clear_flash_buffer ();
void crc_flash_buffer ();

int rand();

/* Clock */
void initRTC ();
int readRTC ();
void clearRTC ();
void initTMR4 ();
void delayMS (int delay);  // delay up to 100000 millisecs (100 secs)


#endif

